#include "FPSCamera.h"
#include "Object3D/Object3D.h"
#include "Utils/MathUtils.h"
#include <assert.h>

#if defined (_DEBUG)
#include "Memory/MemLeaks.h"
#endif

//-------------------------------------------------
CFPSCamera::CFPSCamera(float _fZNear, float _fZFar, float _fFOV, float _fAspectRatio, CObject3D* _pObject)
	: CCamera(_fZNear, _fZFar, _fFOV, _fAspectRatio, _pObject)
{

}

//-------------------------------------------------
CFPSCamera::CFPSCamera()
	: CCamera()
{

}

//-------------------------------------------------
CFPSCamera::~CFPSCamera()
{

}

//-------------------------------------------------
Vect3f CFPSCamera::GetDirection() const
{
	assert(m_pObject3D);
	return (GetLookAt() - GetEye());
}

//-------------------------------------------------
Vect3f CFPSCamera::GetEye() const
{
	assert(m_pObject3D);
	return m_pObject3D->GetPosition();
}

//-------------------------------------------------
Vect3f CFPSCamera::GetLookAt() const
{
	assert(m_pObject3D);

	float yaw	= m_pObject3D->GetYaw();
	float pitch	= m_pObject3D->GetPitch();
	Vect3f pos	= m_pObject3D->GetPosition();

	//Pasamos de coordenadas esfericas a coordenadas cartesianas
	Vect3f vEyePt(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch));

	return (pos + vEyePt);
}

//-------------------------------------------------
Vect3f CFPSCamera::GetVecUp() const
{
	assert(m_pObject3D);

	float yaw	= m_pObject3D->GetYaw();
	float pitch	= m_pObject3D->GetPitch();

	Vect3f vUpVec(-cos(yaw) * sin(pitch), cos(pitch), -sin(yaw) * sin(pitch) );

	vUpVec.y = Math::Utils::Abs(vUpVec.y);

	return vUpVec;
}